<?php
namespace App\Http\Controllers\System;

use App\Http\Controllers\Controller;
use App\Common\Utils\JsonResponse;
use Illuminate\Http\Request;

class DefinedGroupController extends Controller
{

    private $logService;
    private $Request;
    private $definedGroupService;
  
    public function __construct(Request $Request)
    {
        parent::__construct();
        /** @var \App\Services\System\LogService $logService */
        $this->logService = app('logService');
        /** @var \App\Services\System\definedGroupService $definedGroupService */
        $this->definedGroupService = app('definedGroupService');
        $this->Request = $Request;
    }

    /**
     * 一级分组列表
     * @author lxy
     * @datetime 2022-11-22
     */
    public function getDgList()
    {
        try{
            $result = $this->definedGroupService->getDgList($this->Request->all());
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * 第二级分组列表数据
     * @author lxy
     * @datetime 2022-11-22
     */
    public function getDgTwoList()
    {
        try{
            $result = $this->definedGroupService->getDgTwoList($this->Request->all());
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * 第三级分组列表数据
     * @author lxy
     * @datetime 2022-11-22
     */
    public function getDgThreeList()
    {
        try{
            $result = $this->definedGroupService->getDgThreeList($this->Request->all());
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * 添加分组
     * @author lxy
     * @datetime 2022-11-22
     */
    public function addDf()
    {
        try{
            $result = $this->definedGroupService->addDf($this->Request->all());
            if(!empty($this->Request->all()['id'])){
                $this->logService->log('49','编辑分组', "编辑分组");
            }else{
                $this->logService->log('49','添加分组', "添加分组");
            }       
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * 删除
     * @author lxy
     * @datetime 2022-11-22
     */ 
    public function delDf()
    {
        try{
            $result = $this->definedGroupService->delDf($this->Request->all());
            $this->logService->log('51','删除分组/用户', "删除分组/用户");
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * 批量删除
     * @author lxy
     * @datetime 2022-11-22
     */ 
    public function delAllDf()
    {
        try{
            $result = $this->definedGroupService->delAllDf($this->Request->all());
            $this->logService->log('54','批量删除用户', "批量删除用户");
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * 添加人员
     * @author lxy
     * @datetime 2022-11-22
     */
    public function addDfMembers()
    {
        try{
            $result = $this->definedGroupService->addDfMembers($this->Request->all());
            $this->logService->log('53','添加人员', "添加人员");
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * 人员选择渲染
     * @author lxy
     * @datetime 2022-11-23
     */
    public function getDfMembers()
    {
        try{
            $result = $this->definedGroupService->getDfMembers($this->Request->all());
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * 获取自定义分组成员
     * @author lxy
     * @datetime 2022-11-24
     */
    public function getDfGroupMembers()
    {
        try{
            $result = $this->definedGroupService->getDfGroupMembers($this->Request->all());
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * 获取分组成员
     * @author lxy
     * @datetime 2022-11-24
     */
    public function getDfMembersToId()
    {
        try{
            $result = $this->definedGroupService->getDfMembersToId($this->Request->all());
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

}

?>